package com.coder.config;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;

import java.io.IOException;

/**
 * @author 王令
 */
public class HttpUtils {

    public static Connection getHttpConnection(String url){
        Connection connect = Jsoup.connect(url);
        connect.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
        connect.header("Accept-Encoding", "gzip, deflate, br");
        connect.header("Accept-Language", "zh-CN,zh;q=0.9");
        connect.header("Cache-Control", "max-age=0");
        connect.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4573.0 Safari/537.36");
        connect.ignoreHttpErrors(true);
        return connect;
    }

    public static Element getBodyElement(String url) throws IOException {
        Connection.Response response = getHttpConnection(url).execute();
        return response.parse().body();
    }

}
